﻿Public Class frmAccidentes
    Dim acc As New clsAccidentes
    Dim Bitacora As New clsActividad
    Private Sub frmAccidentes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip2.Cursor = Cursors.Hand
        ToolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        ToolStrip2.Stretch = True

        If EmpleadoID = 0 Then
            limpiaCampos()
        Else
            limpiaCampos()
            Me.txtID.Text = EmpleadoID
            Me.txtNomEmp.Text = frmModuloEmpleadosDetalle.txtPaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtMaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtNombre.Text.Trim
            Me.txtDepto.Text = frmModuloEmpleadosDetalle.txtDepartamento.Text

        End If
    End Sub

    Private Sub txtMonto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMonto.TextChanged
        Dim monto As Double = Me.txtMonto.Text

        If monto > 0 Then
            If Me.lstResponsa.Text = "" Then
                MsgBox("Para indicar el monto del accidente debes indicar la responsabilidad", MsgBoxStyle.Exclamation, "Aviso")
                Me.txtMonto.Text = 0
                Exit Sub
            Else
                If Me.lstResponsa.Text = "Vehiculo 1" Then
                    monto = monto * 0.4
                    Me.txtCobro.Text = monto
                End If
            End If
        End If
    End Sub
    Sub limpiaCampos()
        Me.txtID.Clear()
        Me.txtNomEmp.Clear()
        Me.datfecha.Value = Now()
        Me.datHora.Value = Now()
        Me.txtLugar.Clear()
        Me.lstResponsa.Text = ""
        Me.lstSeveridad.Text = ""
        Me.txtCausa.Text = ""
        Me.txtMonto.Text = 0
        Me.txtCobro.Text = 0
        Me.txtDepto.Clear()
        Me.txtAutobus.Clear()
        Me.txtFolio.Clear()


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
    Private Sub gatter()
        acc.idAccidente = (BuscarIntDatoCitra("Select max(IdAccidente) as Id FROM Accidentes")) + 1
        acc.idempleado = Me.txtID.Text
        acc.fecha = Me.datfecha.Value
        acc.Hora = Me.datHora.Value
        acc.Lugar = Me.txtLugar.Text
        acc.Responsabilidad = Me.lstResponsa.Text
        acc.Severidad = Me.lstSeveridad.Text
        acc.Monto = Me.txtMonto.Text
        acc.Cobro = Me.txtCobro.Text
        acc.Causa = Me.txtCausa.Text
        acc.Autobus = Me.txtAutobus.Text
        acc.Ruta = Me.txtDepto.Text
        acc.Usuario = usuarioactivo
        acc.Tipo = "Accidente"
        acc.Reportado = "No"
        acc.Enviado = "No"
        acc.Folio = Me.txtFolio.Text
        acc.Destino = ""
        acc.FechaRegistro = datRegistro.Value

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(5)
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
            Me.txtNomEmp.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(2).Value.ToString())
            Me.txtID.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(1).Value.ToString())
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(1)
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
            Me.txtDepto.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(2).Value.ToString())
        End If
    End Sub

    Private Sub lstResponsa_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstResponsa.SelectedIndexChanged
        If Me.lstResponsa.Text = "Vehiculo 1" Then
            If Me.txtMonto.Text > 0 Then
                Me.txtCobro.Text = Me.txtMonto.Text * 0.4
            End If
        ElseIf Me.lstResponsa.Text = "Vehiculo 2" Then
            If Me.txtMonto.Text > 0 Then
                Me.txtCobro.Text = Me.txtMonto.Text * 0
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub toolGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub toolSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub ToolStripButton5_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton5.Click
        If Me.txtID.Text = "" Then
            MsgBox("Debes indicar un empleado", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtDepto.Text = "" Then
            MsgBox("Debes indicar un departamento", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtAutobus.Text = "" Then
            MsgBox("Debes indicar un numero economico", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtLugar.Text = "" Then
            MsgBox("Debes indicar el lugar del accidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstSeveridad.Text = "" Then
            MsgBox("Debes indicar la severidad del accidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstResponsa.Text = "" Then
            MsgBox("Debes indicar la responsabilidad del accidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtCausa.Text = "" Then
            MsgBox("Debes indicar la causa del accidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtMonto.Text = "" Then
            Me.txtCobro.Text = 0
            Me.txtMonto.Text = 0
        End If

        If Me.txtCobro.Text = "" Then
            Me.txtCobro.Text = 0
        End If
        gatter()

        acc.Insertar()
        'Registra actividad
        Bitacora.RegistraActividad("Registró un accidente a " & txtNomEmp.Text.Trim)

        limpiaCampos()

        frmModuloEmpleadosDetalle.cargaAccidentes()
        Close()

    End Sub

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
        Me.Close()
    End Sub
End Class